<?php
namespace app\admin\controller;

use app\common\controller\AdminBaseController;
use app\common\enum\IsDelete;
use app\common\ext\IDb;
use app\common\ext\IRequest;

class UserQuota extends AdminBaseController{

    /**
     * @功能：用户征信信息
     * @开发者：cxl
     * @return string
     */
    public function user_quota_list(){
        //接收参数
        $user_id = IRequest::get('user_id');
        $quota_item_id = IRequest::get('quota_item_id');

        //取得代理商数据
        $where = null;
        $where['is_delete'] = IsDelete::No;
        $user_quota_item_list = IDb::getInstance('user_quota_item')->setDbWhere($where)->setDbOrder("quota_item_id")->sel();

        //设置查询条件
        $where = null;
        if(!empty($user_id)) $where['user_id'] = $user_id;
        if(!empty($quota_item_id)) $where['quota_item_id'] = $quota_item_id;
        $user_quota_details_list = IDb::getInstance('user_quota_details')->setDbWhere($where)->setDbOrder("user_id,quota_item_id desc")->pag();

        //判断数据是否正确
        if(!empty($user_quota_details_list) && is_array($user_quota_details_list)){
            foreach($user_quota_details_list as &$user_quota_details){
                //请求参数
                $user_quota_details['param_data'] = json_decode($user_quota_details['param_data'],true);
                if(empty($user_quota_details['param_data']) || !is_array($user_quota_details['param_data'])){
                    $user_quota_details['param_data'] = array();
                }

                //返回值结果
                $user_quota_details['result_data'] = json_decode($user_quota_details['result_data'],true);
                if(empty($user_quota_details['result_data']) || !is_array($user_quota_details['result_data'])){
                    $user_quota_details['result_data'] = array();
                }
            }
        }else{
            $user_quota_details_list = array();
        }

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("quota_item_id",$quota_item_id);
        $this->assign("user_quota_item_list",$user_quota_item_list);
        $this->assign("user_quota_details_list",$user_quota_details_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：用户征信信息详情
     * @开发者：cxl
     * @return string
     */
    public function user_quota_details_info(){
        //接收参数
        $quota_details_id = IRequest::get("quota_details_id",IRequest::NOT_EMPTY,"用户征信编号不能为空！");

        //设置查询条件
        $where['quota_details_id'] = $quota_details_id;
        $user_quota_details_info = IDb::getInstance('user_quota_details')->setDbWhere($where)->row();
        if(!empty($user_quota_details_info) || is_array($user_quota_details_info)){
            //请求参数
            $user_quota_details_info['param_data'] = json_decode($user_quota_details_info['param_data'],true);
            if(empty($user_quota_details_info['param_data']) || !is_array($user_quota_details_info['param_data'])){
                $user_quota_details_info['param_data'] = array();
            }

            //返回值结果
            $user_quota_details_info['result_data'] = json_decode($user_quota_details_info['result_data'],true);
            if(empty($user_quota_details_info['result_data']) || !is_array($user_quota_details_info['result_data'])){
                $user_quota_details_info['result_data'] = array();
            }
        }

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("user_quota_details_info",$user_quota_details_info);

        //渲染模板输出
        return view();
    }
}
